import java.awt.SystemColor;

/*
 * FerramentasDesenhoPanel.java
 *
 * Created on 5 de Julho de 2005, 22:38
 */

/**
 *
 * @author  Administrador
 */
public class FerramentasDesenhoPanel extends javax.swing.JPanel {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 3635627474046177832L;
	SAPO sapo;
    
    /** Creates new form FerramentasDesenhoPanel */
    public FerramentasDesenhoPanel(SAPO sapo) {
        this.sapo = sapo;
        SAPO.setLookAndFeel(this);
        initComponents();
    }
    
    public void resetButtons() {
    	jtbtnNone.doClick();
    }
    
    public void resetColor() {
    	jbtnSelCor.setBackground(SystemColor.control);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        btnGroupDesenho = new javax.swing.ButtonGroup();
        jdlgCor = new javax.swing.JDialog();
        jColorChooser1 = new javax.swing.JColorChooser();
        jPanel1 = new javax.swing.JPanel();
        jbtnOkCor = new javax.swing.JButton();
        jbtnCancelCor = new javax.swing.JButton();
        toolBar = new javax.swing.JToolBar();
        jtbtnLine = new javax.swing.JToggleButton();
        jtbtnRect = new javax.swing.JToggleButton();
        jtbRetangulo = new javax.swing.JToggleButton();
        jtbtnCircle = new javax.swing.JToggleButton();
        jtbtnTexto = new javax.swing.JToggleButton();
        jPanel4 = new javax.swing.JPanel();
        jtbtnNone = new javax.swing.JToggleButton();
        jbtnSelCor = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jSpinner1 = new javax.swing.JSpinner();
        jPanel6 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jcmbBoxFonte = new javax.swing.JComboBox();
        jcmbBoxFonteTam = new javax.swing.JComboBox();
        jPanel8 = new javax.swing.JPanel();
        jbtnOkDesenho = new javax.swing.JButton();
        jbtnCancelDesenho = new javax.swing.JButton();

        jColorChooser1.setColor(new java.awt.Color(255, 0, 0));
        jColorChooser1.setMinimumSize(new java.awt.Dimension(400, 340));
        jColorChooser1.setPreferredSize(new java.awt.Dimension(400, 340));
        jdlgCor.getContentPane().add(jColorChooser1, java.awt.BorderLayout.CENTER);

        jbtnOkCor.setText("Ok");
        jbtnOkCor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnOkCorActionPerformed(evt);
            }
        });

        jPanel1.add(jbtnOkCor);

        jbtnCancelCor.setText("Cancel");
        jbtnCancelCor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnCancelCorActionPerformed(evt);
            }
        });

        jPanel1.add(jbtnCancelCor);

        jdlgCor.getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);

        setLayout(new java.awt.BorderLayout());

        toolBar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        toolBar.setFloatable(false);
        toolBar.setRollover(true);
        toolBar.setToolTipText("");
        toolBar.setAlignmentX(0.0F);
        toolBar.setMaximumSize(new java.awt.Dimension(9999, 9999));
        toolBar.setMinimumSize(new java.awt.Dimension(28, 28));
        toolBar.setName("SAPO - Ferramentas");
        btnGroupDesenho.add(jtbtnLine);
        jtbtnLine.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/line.gif")));
        jtbtnLine.setToolTipText("Desenhar linhas");
        jtbtnLine.setMaximumSize(new java.awt.Dimension(30, 30));
        jtbtnLine.setMinimumSize(new java.awt.Dimension(24, 24));
        jtbtnLine.setPreferredSize(new java.awt.Dimension(30, 30));
        jtbtnLine.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtbtnLineActionPerformed(evt);
            }
        });

        toolBar.add(jtbtnLine);

        btnGroupDesenho.add(jtbtnRect);
        jtbtnRect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/retan_line.gif")));
        jtbtnRect.setToolTipText("Desenhar ret\u00e2ngulos");
        jtbtnRect.setMaximumSize(new java.awt.Dimension(30, 30));
        jtbtnRect.setMinimumSize(new java.awt.Dimension(24, 24));
        jtbtnRect.setPreferredSize(new java.awt.Dimension(30, 30));
        jtbtnRect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtbtnRectActionPerformed(evt);
            }
        });

        toolBar.add(jtbtnRect);

        btnGroupDesenho.add(jtbRetangulo);
        jtbRetangulo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/retangulo.gif")));
        jtbRetangulo.setToolTipText("Desenhar ret\u00e2ngulos com preenchimento");
        jtbRetangulo.setMaximumSize(new java.awt.Dimension(30, 30));
        jtbRetangulo.setMinimumSize(new java.awt.Dimension(24, 24));
        jtbRetangulo.setPreferredSize(new java.awt.Dimension(30, 30));
        jtbRetangulo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtbRetanguloActionPerformed(evt);
            }
        });

        toolBar.add(jtbRetangulo);

        btnGroupDesenho.add(jtbtnCircle);
        jtbtnCircle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/circulo.gif")));
        jtbtnCircle.setToolTipText("Desenhar elipses");
        jtbtnCircle.setMaximumSize(new java.awt.Dimension(30, 30));
        jtbtnCircle.setMinimumSize(new java.awt.Dimension(24, 24));
        jtbtnCircle.setPreferredSize(new java.awt.Dimension(30, 30));
        jtbtnCircle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtbtnCircleActionPerformed(evt);
            }
        });

        toolBar.add(jtbtnCircle);

        btnGroupDesenho.add(jtbtnTexto);
        jtbtnTexto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/texto.gif")));
        jtbtnTexto.setToolTipText("Escrever textos");
        jtbtnTexto.setMaximumSize(new java.awt.Dimension(30, 30));
        jtbtnTexto.setMinimumSize(new java.awt.Dimension(24, 24));
        jtbtnTexto.setPreferredSize(new java.awt.Dimension(30, 30));
        jtbtnTexto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtbtnTextoActionPerformed(evt);
            }
        });

        toolBar.add(jtbtnTexto);

        jPanel4.setMaximumSize(new java.awt.Dimension(15, 32767));
        jPanel4.setOpaque(false);
        jPanel4.setPreferredSize(new java.awt.Dimension(15, 10));
        btnGroupDesenho.add(jtbtnNone);
        jtbtnNone.setToolTipText("");
        jtbtnNone.setMaximumSize(new java.awt.Dimension(0, 0));
        jtbtnNone.setMinimumSize(new java.awt.Dimension(0, 0));
        jtbtnNone.setPreferredSize(new java.awt.Dimension(0, 0));
        jPanel4.add(jtbtnNone);

        toolBar.add(jPanel4);

        jbtnSelCor.setFont(new java.awt.Font("SansSerif", 1, 11));
        jbtnSelCor.setForeground(new java.awt.Color(153, 0, 153));
        jbtnSelCor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/cor.png")));
        jbtnSelCor.setToolTipText("Definir cor");
        jbtnSelCor.setMaximumSize(new java.awt.Dimension(30, 30));
        jbtnSelCor.setMinimumSize(new java.awt.Dimension(30, 30));
        jbtnSelCor.setPreferredSize(new java.awt.Dimension(30, 30));
        jbtnSelCor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSelCorActionPerformed(evt);
            }
        });

        toolBar.add(jbtnSelCor);

        jPanel5.setMaximumSize(new java.awt.Dimension(15, 32767));
        jPanel5.setOpaque(false);
        jPanel5.setPreferredSize(new java.awt.Dimension(15, 10));
        toolBar.add(jPanel5);

        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jPanel2.setMaximumSize(new java.awt.Dimension(350, 32767));
        jPanel2.setMinimumSize(new java.awt.Dimension(258, 25));
        jLabel1.setText("Espessura:");
        jPanel2.add(jLabel1);

        jSpinner1.setToolTipText("Seleciona a espessura da linha");
        jSpinner1.setMinimumSize(new java.awt.Dimension(40, 18));
        jSpinner1.setPreferredSize(new java.awt.Dimension(40, 18));
        jSpinner1.setValue(new Integer(1));
        jSpinner1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner1StateChanged(evt);
            }
        });

        jPanel2.add(jSpinner1);

        jPanel6.setMaximumSize(new java.awt.Dimension(15, 32767));
        jPanel6.setOpaque(false);
        jPanel6.setPreferredSize(new java.awt.Dimension(15, 10));
        jPanel2.add(jPanel6);

        jLabel2.setText("Fonte:");
        jPanel2.add(jLabel2);

        jcmbBoxFonte.setToolTipText("Seleciona a fonte do texto");
        jcmbBoxFonte.setMaximumSize(new java.awt.Dimension(70, 20));
        sapo.fonteTextoGraph = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
        for(int i=0; i<sapo.fonteTextoGraph.length; i++){
            jcmbBoxFonte.addItem(sapo.fonteTextoGraph[i].getName());
        }
        jcmbBoxFonte.setSelectedIndex(12);
        jcmbBoxFonte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcmbBoxFonteActionPerformed(evt);
            }
        });

        jPanel2.add(jcmbBoxFonte);

        jcmbBoxFonteTam.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "8", "10", "12", "14", "16", "18", "20", "22", "24", "26", "28", "30", "35", "40" }));
        jcmbBoxFonteTam.setToolTipText("Seleciona o tamanho da fonte");
        jcmbBoxFonteTam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcmbBoxFonteTamActionPerformed(evt);
            }
        });

        jPanel2.add(jcmbBoxFonteTam);

        toolBar.add(jPanel2);

        jPanel8.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        jbtnOkDesenho.setText("Ok");
        jbtnOkDesenho.setToolTipText("Salva as altera\u00e7\u00f5es na figura");
        jbtnOkDesenho.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jbtnOkDesenho.setMaximumSize(new java.awt.Dimension(60, 23));
        jbtnOkDesenho.setMinimumSize(new java.awt.Dimension(47, 23));
        jbtnOkDesenho.setPreferredSize(new java.awt.Dimension(60, 23));
        jbtnOkDesenho.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnOkDesenhoActionPerformed(evt);
            }
        });

        jPanel8.add(jbtnOkDesenho);

        jbtnCancelDesenho.setText("Cancelar");
        jbtnCancelDesenho.setToolTipText("Cancela as altera\u00e7\u00f5es");
        jbtnCancelDesenho.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jbtnCancelDesenho.setMaximumSize(new java.awt.Dimension(60, 23));
        jbtnCancelDesenho.setMinimumSize(new java.awt.Dimension(47, 23));
        jbtnCancelDesenho.setPreferredSize(new java.awt.Dimension(60, 23));
        jbtnCancelDesenho.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnCancelDesenhoActionPerformed(evt);
            }
        });

        jPanel8.add(jbtnCancelDesenho);

        toolBar.add(jPanel8);

        add(toolBar, java.awt.BorderLayout.NORTH);

    }
    // </editor-fold>//GEN-END:initComponents

    private void jbtnOkCorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnOkCorActionPerformed
//Anderson Zanardi de Freitas
        sapo.corDesenho = jColorChooser1.getColor();
        jbtnSelCor.setBackground(sapo.corDesenho);
        jdlgCor.setVisible(false);
    }//GEN-LAST:event_jbtnOkCorActionPerformed

    private void jbtnCancelCorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCancelCorActionPerformed
    	jdlgCor.setVisible(false); 
    	jtbtnNone.doClick();
    }//GEN-LAST:event_jbtnCancelCorActionPerformed

    private void jbtnCancelDesenhoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCancelDesenhoActionPerformed
    	resetButtons();
    	sapo.showInternalFrameWithImage(sapo.numImg);
        sapo.release();
    }//GEN-LAST:event_jbtnCancelDesenhoActionPerformed

    private void jbtnSelCorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSelCorActionPerformed
        jdlgCor.pack();
        jdlgCor.setVisible(true); 
        sapo.corDesenho = jColorChooser1.getColor();
    }//GEN-LAST:event_jbtnSelCorActionPerformed

    private void jbtnOkDesenhoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnOkDesenhoActionPerformed
    	jtbtnNone.doClick();
    	sapo.frmDesenho.aceitaAlteracao();
        sapo.frmImagem.inicializaParametros();
    }//GEN-LAST:event_jbtnOkDesenhoActionPerformed
                         
    
    private void jtbtnTextoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtbtnTextoActionPerformed
        sapo.desacoplar(sapo.numImg);
        sapo.frmDesenho.acoplar(sapo.numImg);
        sapo.desenhoTipo = 3; // 3 = Texto
    }//GEN-LAST:event_jtbtnTextoActionPerformed

    private void jtbtnCircleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtbtnCircleActionPerformed
        sapo.desacoplar(sapo.numImg);
        sapo.frmDesenho.acoplar(sapo.numImg);
        sapo.desenhoTipo = 2; // 2 = Circulo
        sapo.espLinha = ((Integer)jSpinner1.getValue()).intValue();
    }//GEN-LAST:event_jtbtnCircleActionPerformed

    private void jtbtnRectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtbtnRectActionPerformed
        sapo.desacoplar(sapo.numImg);
        sapo.frmDesenho.acoplar(sapo.numImg);
        sapo.desenhoTipo = 1; // 1 = Retangulo
        sapo.espLinha = ((Integer)jSpinner1.getValue()).intValue();
    }//GEN-LAST:event_jtbtnRectActionPerformed

    private void jtbtnLineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtbtnLineActionPerformed
        sapo.desacoplar(sapo.numImg);
        sapo.frmDesenho.acoplar(sapo.numImg);
        sapo.desenhoTipo = 0; // 0 = Line
        sapo.espLinha = ((Integer)jSpinner1.getValue()).intValue();
    }//GEN-LAST:event_jtbtnLineActionPerformed

    private void jtbRetanguloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtbRetanguloActionPerformed
       /* if (jtbRetangulo.isSelected()) sapo.mostraPainelRetangulo(true); 
                                  else sapo.mostraPainelRetangulo(false); 
        */
       sapo.desacoplar(sapo.numImg);
       sapo.frmDesenho.acoplar(sapo.numImg);
       sapo.desenhoTipo = 4; // 4 = Retangulo Cheio
       sapo.espLinha = ((Integer)jSpinner1.getValue()).intValue(); 
    }//GEN-LAST:event_jtbRetanguloActionPerformed

    private void jcmbBoxFonteTamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmbBoxFonteTamActionPerformed
    	jcmbBoxFonteActionPerformed(evt);
    }//GEN-LAST:event_jcmbBoxFonteTamActionPerformed

    private void jcmbBoxFonteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmbBoxFonteActionPerformed
        String txtFonte = (String)jcmbBoxFonte.getSelectedItem();
        int fonteTam = (Integer.valueOf((String)jcmbBoxFonteTam.getSelectedItem())).intValue();
        sapo.fonteAtual = new java.awt.Font(txtFonte, java.awt.Font.BOLD, fonteTam);
    }//GEN-LAST:event_jcmbBoxFonteActionPerformed

    private void jSpinner1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner1StateChanged
        sapo.espLinha = ((Integer)jSpinner1.getValue()).intValue();
    }//GEN-LAST:event_jSpinner1StateChanged
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup btnGroupDesenho;
    private javax.swing.JColorChooser jColorChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JSpinner jSpinner1;
    private javax.swing.JButton jbtnCancelCor;
    private javax.swing.JButton jbtnCancelDesenho;
    private javax.swing.JButton jbtnOkCor;
    private javax.swing.JButton jbtnOkDesenho;
    private javax.swing.JButton jbtnSelCor;
    public javax.swing.JComboBox jcmbBoxFonte;
    private javax.swing.JComboBox jcmbBoxFonteTam;
    private javax.swing.JDialog jdlgCor;
    public javax.swing.JToggleButton jtbRetangulo;
    private javax.swing.JToggleButton jtbtnCircle;
    private javax.swing.JToggleButton jtbtnLine;
    private javax.swing.JToggleButton jtbtnNone;
    private javax.swing.JToggleButton jtbtnRect;
    private javax.swing.JToggleButton jtbtnTexto;
    public javax.swing.JToolBar toolBar;
    // End of variables declaration//GEN-END:variables
    
}
